
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<base target="_top">

<style type="text/css">
  

/* default css */

table {
  font-size: 1em;
  line-height: inherit;
}


tr {
  
  text-align: left;
  
}


div, address, ol, ul, li, option, select {
  margin-top: 0px;
  margin-bottom: 0px;
}

p {
  margin: 0px;
}

body {
  margin: 6px;
  padding: 0px;
  font-family: Verdana, sans-serif;
  font-size: 10pt;
  background-color: #ffffff;
}


img {
  -moz-force-broken-image-icon: 1;
}

@media screen {
  html.pageview {
    background-color: #f3f3f3 !important;
  }

  

  body {
    min-height: 1100px;
    
    counter-reset: __goog_page__;
  }
  * html body {
    height: 1100px;
  }
  .pageview body {
    border-top: 1px solid #ccc;
    border-left: 1px solid #ccc;
    border-right: 2px solid #bbb;
    border-bottom: 2px solid #bbb;
    width: 648px !important;
    margin: 15px auto 25px;
    padding: 40px 50px;
  }
  /* IE6 */
  * html {
    overflow-y: scroll;
  }
  * html.pageview body {
    overflow-x: auto;
  }
  /* Prevent repaint errors when scrolling in Safari. This "Star-7" css hack
     targets Safari 3.1, but not WebKit nightlies and presumably Safari 4.
     That's OK because this bug is fixed in WebKit nightlies/Safari 4 :-). */
  html*#wys_frame::before {
    content: '\A0';
    position: fixed;
    overflow: hidden;
    width: 0;
    height: 0;
    top: 0;
    left: 0;
  }
  
  

  
    .writely-callout-data {
      display: none;
      *display: inline-block;
      *width: 0;
      *height: 0;
      *overflow: hidden;
    }
    .writely-footnote-marker {
      background-image: url('MISSING');
      background-color: transparent;
      background-repeat: no-repeat;
      width: 7px;
      overflow: hidden;
      height: 16px;
      vertical-align: top;

      
      -moz-user-select: none;
    }
    .editor .writely-footnote-marker {
      cursor: move;
    }
    .writely-footnote-marker-highlight {
      background-position: -15px 0;
      -moz-user-select: text;
    }
    .writely-footnote-hide-selection ::-moz-selection, .writely-footnote-hide-selection::-moz-selection {
      background: transparent;
    }
    .writely-footnote-hide-selection ::selection, .writely-footnote-hide-selection::selection {
      background: transparent;
    }
    .writely-footnote-hide-selection {
      cursor: move;
    }

    
    .editor .writely-comment-yellow {
      background-color: #FF9;
      background-position: -240px 0;
    }
    .editor .writely-comment-yellow-hover {
      background-color: #FF0;
      background-position: -224px 0;
    }
    .editor .writely-comment-blue {
      background-color: #C0D3FF;
      background-position: -16px 0;
    }
    .editor .writely-comment-blue-hover {
      background-color: #6292FE;
      background-position: 0 0;
    }
    .editor .writely-comment-orange {
      background-color: #FFDEAD;
      background-position: -80px 0;
    }
    .editor .writely-comment-orange-hover {
      background-color: #F90;
      background-position: -64px 0;
    }
    .editor .writely-comment-green {
      background-color: #99FBB3;
      background-position: -48px 0;
    }
    .editor .writely-comment-green-hover {
      background-color: #00F442;
      background-position: -32px 0;
    }
    .editor .writely-comment-cyan {
      background-color: #CFF;
      background-position: -208px 0;
    }
    .editor .writely-comment-cyan-hover {
      background-color: #0FF;
      background-position: -192px 0;
    }
    .editor .writely-comment-purple {
      background-color: #EBCCFF;
      background-position: -144px 0;
    }
    .editor .writely-comment-purple-hover {
      background-color: #90F;
      background-position: -128px 0;
    }
    .editor .writely-comment-magenta {
      background-color: #FCF;
      background-position: -112px 0;
    }
    .editor .writely-comment-magenta-hover {
      background-color: #F0F;
      background-position: -96px 0;
    }
    .editor .writely-comment-red {
      background-color: #FFCACA;
      background-position: -176px 0;
    }
    .editor .writely-comment-red-hover {
      background-color: #FF7A7A;
      background-position: -160px 0;
    }

    .editor .writely-comment-marker {
      background-image: url('MISSING');
      background-color: transparent;
      padding-right: 11px;
      background-repeat: no-repeat;
      width: 16px;
      height: 16px;
      -moz-user-select: none;
    }

    .editor .writely-comment-hidden {
      padding: 0;
      background: none;
    }
    .editor .writely-comment-marker-hidden {
      background: none;
      padding: 0;
      width: 0;
    }
    .editor .writely-comment-none {
      opacity: .2;
      filter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);
      -moz-opacity: .2;
    }
    .editor .writely-comment-none-hover {
      opacity: .2;
      filter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);
      -moz-opacity: .2;
    }
  


  
  .br_fix br:not(:-moz-last-node):not(:-moz-first-node) {
    
    position:relative;
    
    left: -1ex
    
  }
  
  .br_fix br+br {
    position: static !important
  }
}

h6 { font-size: 8pt }
h5 { font-size: 8pt }
h4 { font-size: 10pt }
h3 { font-size: 12pt }
h2 { font-size: 14pt }
h1 { font-size: 18pt }

blockquote {padding: 10px; border: 1px #DDD dashed }

a img {border: 0}

.pb {
  border-width: 0;
  page-break-after: always;
  /* We don't want this to be resizeable, so enforce a width and height
     using !important */
  height: 1px !important;
  width: 100% !important;
}

.editor .pb {
  border-top: 1px dashed #C0C0C0;
  border-bottom: 1px dashed #C0C0C0;
}

div.google_header, div.google_footer {
  position: relative;
  margin-top: 1em;
  margin-bottom: 1em;
}


/* Table of contents */
.editor div.writely-toc {
  background-color: #f3f3f3;
  border: 1px solid #ccc;
}
.writely-toc > ol {
  padding-left: 3em;
  font-weight: bold;
}
ol.writely-toc-subheading {
  padding-left: 1em;
  font-weight: normal;
}
/* IE6 only */
* html writely-toc ol {
  list-style-position: inside;
}
.writely-toc-none {
  list-style-type: none;
}
.writely-toc-decimal {
  list-style-type: decimal;
}
.writely-toc-upper-alpha {
  list-style-type: upper-alpha;
}
.writely-toc-lower-alpha {
  list-style-type: lower-alpha;
}
.writely-toc-upper-roman {
  list-style-type: upper-roman;
}
.writely-toc-lower-roman {
  list-style-type: lower-roman;
}
.writely-toc-disc {
  list-style-type: disc;
}

/* end default css */


  /* default print css */
  
  @media print {
    body {
      padding: 0;
      margin: 0;
    }

    div.google_header, div.google_footer {
      display: block;
      min-height: 0;
      border: none;
    }

    div.google_header {
      flow: static(header);
    }

    /* used to insert page numbers */
    div.google_header::before, div.google_footer::before {
      position: absolute;
      top: 0;
    }

    div.google_footer {
      flow: static(footer);
    }

    /* always consider this element at the start of the doc */
    div#google_footer {
      flow: static(footer, start);
    }

    span.google_pagenumber {
      content: counter(page);
    }

    span.google_pagecount {
      content: counter(pages);
    }


    callout.google_footnote {
      
      display: prince-footnote;
      footnote-style-position: inside;
      /* These styles keep the footnote from taking on the style of the text
         surrounding the footnote marker. They can be overridden in the
         document CSS. */
      color: #000;
      font-family: Verdana;
      font-size: 10.0pt;
      font-weight: normal;
    }

    /* Table of contents */
    #WritelyTableOfContents a::after {
      content: leader('.') target-counter(attr(href), page);
    }

    #WritelyTableOfContents a {
      text-decoration: none;
      color: black;
    }
  }

  @page {
    @top {
      content: flow(header);
    }
    @bottom {
      content: flow(footer);
    }
    @footnotes {
      border-top: solid black thin;
      padding-top: 8pt;
    }
  }
  /* end default print css */


/* custom css */


/* end custom css */



  /* ui edited css */
  
  body {
    font-family: Verdana;
    
    font-size: 10.0pt;
    line-height: normal;
    background-color: #ffffff;
  }
  /* end ui edited css */



/* editor CSS */
.editor a:visited {color: #551A8B}
.editor table.zeroBorder {border: 1px dotted gray}
.editor table.zeroBorder td {border: 1px dotted gray}
.editor table.zeroBorder th {border: 1px dotted gray}


.editor div.google_header, .editor div.google_footer {
  border: 2px #DDDDDD dashed;
  position: static;
  width: 100%;
  min-height: 2em;
}

.editor .misspell {background-color: yellow}

.editor .writely-comment {
  font-size: 9pt;
  line-height: 1.4;
  padding: 1px;
  border: 1px dashed #C0C0C0
}


/* end editor CSS */

</style>

</head>

<body onload="DoPageLoad();"
    
    revision="cfnx2f69_111dp3jzfgb:107">

    
    
    
<h1>
  Using the Android Native Development Kit (NDK)
</h1>
version 1.3<br>
<br>
<h2>
  Introduction
</h2>
The Android Native Development Kit enables developers to write shared libraries
in C or C++ and call them from Java code. The native shared libraries can be
packaged into apk files along with a normal Android application written in Java,
so that the resulting Android application can be downloaded and installed on an
Android phone.<br>
<br>
The Native Development Kit consists of:<br>
<ul>
  <li>
    C/C++ headers for native APIs<br>
  </li>
  <li>
    C/C++ libraries for native APIs<br>
  </li>
  <li>
    Documentation
  </li>
  <li>
    Sample Code
  </li>
</ul>
<br>
The Native Development Kit is designed to be used with the Android SDK:<br>
<ul>
  <li>
    The NDK is used to create a shared library containing native code.
  </li>
  <li>
    The SDK is used to create an Android application written in Java that calls
    into the native code shared library.
  </li>
</ul>
<h1>
</h1>
<h2>
  Setting up your machine<br>
</h2>
The Native Development Kit may be installed on either Linux or OS X. Developing
under Windows is not yet supported.<br>
<div>
  <h3>
    Linux Installation
  </h3>
  The
  Android&nbsp;build&nbsp;is&nbsp;routinely&nbsp;tested&nbsp;on&nbsp;recent&nbsp;versions&nbsp;of&nbsp;Ubuntu&nbsp;(6.06&nbsp;and&nbsp;later),&nbsp;but
  may work on other distributions as well.<br>
  <h4>
    <a name=TOC-Ubuntu-Linux-i386-></a><span style=FONT-FAMILY:Verdana>Ubuntu
    Linux (i386)</span>
  </h4>
  <div style=FONT-FAMILY:Verdana>
    To set up your Linux development environment, make sure you have the
    following:<span style="WORD-SPACING:0px; FONT-STYLE:normal; FONT-VARIANT:normal; FONT-WEIGHT:normal; font-size-adjust:none; font-stretch:normal; TEXT-TRANSFORM:none; COLOR:#000000; WHITE-SPACE:normal; LETTER-SPACING:normal; border-collapse:separate"><font size=2>
    </font></span>
  </div>
  <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px; FONT-FAMILY:Verdana">
    <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px">
      <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px">
        <ul style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px">
          <li style="MARGIN-TOP:8px; MARGIN-BOTTOM:8px">
            Git 1.5.4 or
            newer<span style="FONT-WEIGHT:normal; WORD-SPACING:0px; TEXT-TRANSFORM:none; COLOR:#000000; FONT-STYLE:normal; WHITE-SPACE:normal; LETTER-SPACING:normal; border-collapse:separate; FONT-VARIANT:normal"><font size=2>.&nbsp;</font></span>
          </li>
        </ul>
      </div>
    </div>
  </div>
  <blockquote style="BORDER:medium none ; MARGIN:0pt 0pt 0pt 40px; PADDING:0px">
    <span style=FONT-FAMILY:arial><span style="FONT-WEIGHT:normal; WORD-SPACING:0px; TEXT-TRANSFORM:none; COLOR:#000000; FONT-STYLE:normal; WHITE-SPACE:normal; LETTER-SPACING:normal; border-collapse:separate; FONT-VARIANT:normal"><span style="FONT-FAMILY:courier new,monospace">$
    </span></span><span style="FONT-FAMILY:courier new,monospace">sudo apt-get
    install git-core<br>
    </span></span>
  </blockquote>
  <div>
    <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px">
      <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px; FONT-FAMILY:arial,sans-serif">
        <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px">
          <h4>
            <a name=TOC-Ubuntu-Linux-amd64-></a><span style=FONT-FAMILY:Verdana>Ubuntu
            Linux (amd64)</span>
          </h4>
          <span style=FONT-FAMILY:Verdana>This has not been as well
          tested.</span>
        </div>
        <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px; FONT-FAMILY:Verdana">
          <br>
        </div>
        <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px; FONT-FAMILY:Verdana">
          The Android build requires a 32-bit build environment:
        </div>
        <div style="MARGIN-TOP:0px; MARGIN-BOTTOM:0px; FONT-FAMILY:Verdana">
          <ul>
            <li>
              Get the packages as listed above in the i386
              instructions:<span style="FONT-WEIGHT:normal; WORD-SPACING:0px; TEXT-TRANSFORM:none; COLOR:#000000; FONT-STYLE:normal; WHITE-SPACE:normal; LETTER-SPACING:normal; border-collapse:separate; FONT-VARIANT:normal">&nbsp;&nbsp;&nbsp;</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
  <blockquote style="BORDER:medium none ; MARGIN:0pt 0pt 0pt 40px; PADDING:0px">
    <span style=FONT-FAMILY:arial><span style="FONT-WEIGHT:normal; WORD-SPACING:0px; TEXT-TRANSFORM:none; COLOR:#000000; FONT-STYLE:normal; WHITE-SPACE:normal; LETTER-SPACING:normal; border-collapse:separate; FONT-VARIANT:normal"><span style="FONT-FAMILY:courier new,monospace">$&nbsp;</span></span><span style="FONT-FAMILY:courier new,monospace">sudo
    apt-get install git-core<br>
    </span></span>
  </blockquote>
  <h4>
    <a name=TOC-Other-Linux></a>Other Linux
  </h4>
  <p>
    There's
    no&nbsp;reason&nbsp;why&nbsp;Android&nbsp;cannot&nbsp;be&nbsp;built&nbsp;on&nbsp;non-Ubuntu&nbsp;systems<span style=FONT-WEIGHT:normal><font size=2>.&nbsp;In&nbsp;general&nbsp;you&nbsp;will&nbsp;need:</font></span>
  </p>
  <ul>
    <li>
      Git&nbsp;1.5.4&nbsp;or&nbsp;newer.&nbsp;You&nbsp;can&nbsp;find&nbsp;it&nbsp;at&nbsp;<a href=http://git.or.cz/ rel=nofollow>http://git.or.cz/</a><span style=FONT-FAMILY:arial></span>
    </li>
  </ul>
  <div>
    <h3>
      Mac OS Installation
    </h3>
    <ul>
      <li>
        <span style=FONT-FAMILY:arial,sans-serif>To build the Android files in a
        Mac OS environment, you need an Intel/x86 machine. The Android build
        system and tools do not support the older PowerPC architecture.</span>
      </li>
      <li>
        <span style=FONT-FAMILY:arial,sans-serif>Android must be built on a
        case-sensitive file system.<br>
        </span>
      </li>
      <ul>
        <li>
          We recommend that you build Android on a partition that has been
          formatted with the "Case-sensitive Journaled HFS+" file system:
        </li>
        <ul>
          <li>
            A case-sensitive file system is required because the sources contain
            files that differ only in case.
          </li>
          <li>
            Journaled systems are more robust. (This is optional, but
            recommended.)
          </li>
          <li>
            HFS+ is required to successfully build Mac OS applications such as
            the Android Emulator for OS X.
          </li>
        </ul>
        <li>
          If you want to avoid partitioning/formatting your hard drive, you can
          use a case-sensitive disk image instead.
        </li>
        <ul>
          <li>
            To create the image:<br>
            <ul>
              <li>
                launch /Applications/Utilities/Disk Utility
              </li>
              <li>
                select "New Image"
              </li>
              <li>
                size: 8 GB (this will work, but you can choose more if you want
                to)
              </li>
              <li>
                volume format: case sensitive, journaled
              </li>
            </ul>
          </li>
          <li>
            This will create a .dmg file which, once mounted, acts as a drive
            with the required formatting for Android development. For a disk
            image named "android.dmg" stored in your home directory, you can add
            the following to your ~/.bash_profile to mount the image when you
            execute "mountAndroid":<br>
            <br>
            <div style=MARGIN-LEFT:40px>
              <span style="FONT-FAMILY:courier new,monospace"># command to mount
              the android file
              image</span><br style="FONT-FAMILY:courier new,monospace">
              <span style="FONT-FAMILY:courier new,monospace">function
              mountAndroid&nbsp; { hdiutil attach ~/android.dmg&nbsp;
              -mountpoint /Volumes/android; }</span><br>
            </div>
            <br>
            Once mounted, you'll do all your work in the "android" volume. You
            can eject it (unmount it) just like you would with an external
            drive.
          </li>
        </ul>
      </ul>
    </ul>
    <div>
      <br>
      <ul>
        <li>
          Install git 1.5.4 or newer. You can find it at
          <a href=http://git.or.cz/ rel=nofollow>http://git.or.cz/</a>
        </li>
      </ul>
      <h2>
        Installing the Android SDK
      </h2>
      The Android NDK uses the Android SDK.&nbsp;You can find the Android SDK at
      <a href=http://code.google.com/android/download.html id=a.-o title=http://code.google.com/android/download.html>http://code.google.com/android/download.html</a><br>
      This version of the Android NDK requires the Cupcake version of the
      Android SDK.<br>
      <br>
      <h2>
        Installing the Prebuilt Native Toolchain<br>
      </h2>
      The NDK uses the prebuilt native toolchain from the Android Open Source
      git repository.<br>
      <br>
      To download the prebuilt native toolchain to your working directory,
      execute the following commands:<br>
      <br>
      <span style="FONT-FAMILY:Courier New"></span>
      <div style=MARGIN-LEFT:40px>
        <span style="FONT-FAMILY:Courier New">git clone
        git://android.git.kernel.org/platform/prebuilt.git</span><br>
        <span style="FONT-FAMILY:Courier New">cd prebuilt</span><br>
        <span style="FONT-FAMILY:Courier New">git checkout -b cupcake -t
        origin/cupcake</span><br>
      </div>
      <div style=MARGIN-LEFT:40px>
        <span style="FONT-FAMILY:Courier New"></span>
      </div>
      <br>
      <h2>
        Setting Environment Variables
      </h2>
      The NDK requires that you set two environment variables:<br>
      <ul>
        <li>
          PREBUILT must be set to the directory that contains the prebuilt
          toolchain. Include the "prebuilt" directory in the path. Example:
          /Volumes/android/prebuilt<br>
        </li>
        <li>
          ANDROID_SDK_BASE must be set to the directory that contains the
          Android SDK. Example: ~/AndroidSDK<br>
        </li>
      </ul>
      <br>
      <h2>
        <span style=FONT-FAMILY:Verdana>Unpacking the NDK</span>
      </h2>
      Unpack the android_pndk.tar.gz into your working directory<br>
      <br>
      <div style=MARGIN-LEFT:40px>
        <span style="FONT-FAMILY:Courier New">tar -zxvf
        android_pndk.tar.gz</span><br>
      </div>
      <br>
      This will create a directory called pndk. It should contain a README.html
      file (this file) and the following directories: config, include, lib, and
      sample.<br>
      <br>
      Look in the "samples" directory for samples showing how to use the NDK.<br>
      <br>
      <br>
    </div>
    <br>
  </div>
  <br>
</div>
<br></body>
</html>